//jqGrid的配置信息
$.jgrid.defaults.width = 1000;
$.jgrid.defaults.responsive = true;
$.jgrid.defaults.styleUI = 'Bootstrap';

var baseURL = "../../";

//工具集合Tools
window.T = {};

// 获取请求参数
// 使用示例
// location.href = http://localhost:8080/index.html?id=123
// T.p('id') --> 123;
var url = function(name) {
	var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
	var r = window.location.search.substr(1).match(reg);
	if(r!=null)return  unescape(r[2]); return null;
};
T.p = url;

//全局配置
$.ajaxSetup({
	dataType: "json",
	cache: false
});

//重写alert
window.alert = function(msg, callback){
	parent.layer.alert(msg, function(index){
		parent.layer.close(index);
		if(typeof(callback) === "function"){
			callback("ok");
		}
	});
}

//重写confirm式样框
window.confirm = function(msg, callback){
	parent.layer.confirm(msg, {btn: ['确定','取消']},
	function(){//确定事件
		if(typeof(callback) === "function"){
			callback("ok");
		}
	});
}

//选择一条记录
function getSelectedRow() {
    var grid = $("#jqGrid");
    var rowKey = grid.getGridParam("selrow");
    if(!rowKey){
    	alert("请选择一条记录");
    	return ;
    }
    
    var selectedIDs = grid.getGridParam("selarrrow");
    if(selectedIDs.length > 1){
    	alert("只能选择一条记录");
    	return ;
    }
    
    return selectedIDs[0];
}

//选择多条记录
function getSelectedRows() {
    var grid = $("#jqGrid");
    var rowKey = grid.getGridParam("selrow");
    if(!rowKey){
    	alert("请选择一条记录");
    	return ;
    }
    
    return grid.getGridParam("selarrrow");
}

//判断是否为空
function isBlank(value) {
    return !value || !/\S/.test(value)
}

//获取一行数据.
function getRowData(id){
	
	var rowData = $("#jqGrid").jqGrid('getRowData',id);
	
    return rowData;
}

Date.prototype.Format = function (fmt) { //author: meizz 
    var o = {
        "M+": this.getMonth() + 1, //月份 
        "d+": this.getDate(), //日 
        "H+": this.getHours(), //小时 
        "m+": this.getMinutes(), //分 
        "s+": this.getSeconds(), //秒 
        "q+": Math.floor((this.getMonth() + 3) / 3), //季度 
        "S": this.getMilliseconds() //毫秒 
    };
    if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
    for (var k in o)
    if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
    return fmt;
}

//搜索的按钮特性
function collapsePanel(btn,target,callbackFn){
	if($("#"+target).is(":visible")){
		$("#"+target).slideUp('slow',function(){//slow
//			callResizeMasterContentHeight();
			if(typeof callbackFn != 'undefined' && callbackFn != undefined && callbackFn != null && typeof callbackFn === 'function'){
				callbackFn();
			}
		});
		$("#"+btn).removeClass("fa-arrow-circle-o-up").addClass("fa fa-arrow-circle-o-down");
	}else{
		$(document.body).css("overflow","hidden");
		$("#"+target).slideDown('slow',function(){
//			callResizeMasterContentHeight();
			if(typeof callbackFn != 'undefined' && callbackFn != undefined && callbackFn != null && typeof callbackFn === 'function'){
				callbackFn();
			}
		});
		setTimeout(function () {
			$(document.body).css("overflow","auto");
		}, 800);
		$("#"+btn).removeClass("fa-arrow-circle-o-up").addClass("fa-arrow-circle-o-up");
	}
}

function tips(info,name){
    layer.tips(info, "#"+name ,{
        // layer.tips(info, $("input[name='"+name+"']") ,{
        tips: [2, '#3c8dbc'],
        time: 3000
    });
}

function scrollto(scrolldom) {
    $('html,body').animate({
        scrollTop:$(scrolldom).offset().top},200
    );
    return false;
};